<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDaiqianTableIndex extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('new_flow_orders',function (Blueprint $table){
            $table->index('loan_requests_id', 'loan_requests_id');
        });

        //用户身份证实名表 user_cert_ocrs
        Schema::table('user_cert_ocrs',function (Blueprint $table){
            $table->index('num', 'num');
        });

        //用户添加银行卡信息表 user_bank_cards
        Schema::table('user_bank_cards',function (Blueprint $table){
            $table->index('uid', 'user_id');
            $table->index('old_kskd_user_id', 'old_kskd_user_id');
        });

        //用户放款信息表 loan_apply
        Schema::table('loan_apply',function (Blueprint $table){
            $table->index('user_id', 'user_id');
            $table->index('bank_card_id', 'bank_card_id');
            $table->index('loan_request_id', 'loan_request_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if(Schema::hasTable('new_flow_orders')){
            Schema::table('new_flow_orders', function (Blueprint $table) {
                $table->dropIndex('loan_requests_id');
            });
        }

        //用户身份证实名表 user_cert_ocrs
        if(Schema::hasTable('user_cert_ocrs')){
            Schema::table('user_cert_ocrs', function (Blueprint $table) {
                $table->dropIndex('num');
            });
        }

        //用户添加银行卡信息表 user_bank_cards
        if(Schema::hasTable('user_bank_cards')){
            Schema::table('user_bank_cards', function (Blueprint $table) {
                $table->dropIndex('user_id');
                $table->dropIndex('old_kskd_user_id');
            });
        }

        //用户放款信息表 loan_apply
        if(Schema::hasTable('loan_apply')){
            Schema::table('loan_apply', function (Blueprint $table) {
                $table->dropIndex('user_id');
                $table->dropIndex('bank_card_id');
                $table->dropIndex('loan_request_id');
            });
        }
    }
}
